package vb.week1.wc;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class WordCountScanner extends WordCount {
	
	protected int nWords = 0;
	protected String fileName = "hoi.txt";
	
	public static void main(String[] arv){
		WordCountScanner wcs = new WordCountScanner();
		wcs.count();
		
		System.out.println("Aantal woorden: " + wcs.getNWords());
	}
	
	public int getNWords(){
		return this.nWords;
	}
	
	public void count(){
		
		Scanner scanner = null;
		try {
			scanner = new Scanner(new File(this.fileName));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		
		int count = 0;
		
		while(scanner.hasNextLine()){
			
			String line = scanner.nextLine();
			Scanner lineScan = new Scanner(line);
			
			while(lineScan.hasNext()){
				lineScan.next();
				count++;
			}
			
		}
		
		this.nWords = count;
		
	}

}
